package com.cjzuji.rental.controller.order;

import com.cjzuji.rental.Bean.ApiDetailRequest;
import com.cjzuji.rental.Bean.ApiQueryRequest;
import com.cjzuji.rental.Bean.ApiResponse;
import com.cjzuji.rental.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
@Api(tags = "订单类")
public class OrderController {
    @Autowired
    OrderService orderService;
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);
    @PostMapping("/getOrderList")
    @ApiOperation(value = "获取订单列表", notes = "获取订单列表")
    public Object getOrderpage(@RequestBody ApiQueryRequest condition, @RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize){
        try {
            Object list = orderService.getOrderList(condition,pageIndex,pageSize);
            return ApiResponse.success(list);
        }catch(Exception e){
            return ApiResponse.error("588","服务器内部错误:"+e.getMessage());
        }
    }
    @PostMapping("/getDetailList")
    @ApiOperation(value = "获取订单详情", notes = "获取订单详情")
    public Object getOrderDetail(@RequestParam String orderId){
        try {
            if (!StringUtils.hasText(orderId)){
                return ApiResponse.error("500","订单ID不能为空");
            }
            ApiDetailRequest detail = orderService.getOrderDetail(Long.valueOf(orderId));
            return ApiResponse.success(detail);
        }catch(Exception e){
            return ApiResponse.error("588","服务器内部错误:"+e.getMessage());
        }
    }
}

